-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store NtLiteral without generalizing to Expr #92392
Conversation
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to check some things before proceeding with changes in this area, cc #92472.
Some random thoughts:
|
Thanks for the review! I can tell I'm not going to change your mind on this so I'll go ahead and close. |
The discussion under #91166 raised the question of whether a NtLiteral (the value of a
$:literal
matcher in macro_rules) can be conceptualized as a single token, the way that$:ident
is. Today it isn't — a negative literal is passed to procedural macros as a pair of proc macro tokens:However proc macro literals already support negative literals in a single token, and it's easy to construct one:
proc_macro::Literal::i32_unsuffixed(-1)
. As such, given that macro_rules's$:literal
and proc_macro::Literal are both already capable of representing negative literals in one piece, I think having those literals fall apart on entry into the proc macro is not a great behavior. My expectation would be that the proc macro call in the snippet above would pass a single token which is equivalent toproc_macro::Literal::i32_unsuffixed(-1)
, and I'd like to start making changes in that direction.This PR does not make any intentional observable behavior change, but it replaces the way that
$:literal
is represented internally fromP<Expr>
(which happens to be always eitherExprKind::Lit
orExprKind::Unary(UnOp::Neg, ExprKind::Lit)
if rustc is correctly implemented) to a dedicatedSignedLiteral
type. This makes illegal states unrepresentable and will make it more straightforward to map$:literal
one-to-one to proc_macro::Literal whenever that comes up.